package com.example.springboot01.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springboot01.entity.Class;
import com.example.springboot01.entity.Professor;
import com.example.springboot01.mapper.ProfessorMapper;
import com.example.springboot01.service.ClassService;
import com.example.springboot01.service.ProfessorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProfessorServiceImpl extends ServiceImpl<ProfessorMapper, Professor> implements ProfessorService {

    @Resource
    private ClassService classService;

    @Override
    public boolean removeProfessor(Integer id) {
        List<Class> classList = classService.queryByProfessor(id);
        if (classList.isEmpty()) {
            // delete professor
            this.removeById(id);
            return true;
        }
        return false;
    }
}
